package com.test.exam.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.test.exam.domain.Admin;
import com.test.exam.service.AdminService;

@Controller
public class AdminController {
	@Autowired
	AdminService adminService;
	
	@RequestMapping(value="/admin/logout",
					method=RequestMethod.GET)
	public String logout(HttpSession session){
		session.invalidate();
		return "redirect:/";
	}
	
	
	@RequestMapping(value="/adminLogin/getAndminByIdAndPw",
					method=RequestMethod.POST)
	public String getAndminByIdAndPw(Admin admin, HttpSession session){
	//	System.out.println("AdminController adminId:"+admin.getAdminId());
	//	System.out.println("AdminController adminPw:"+admin.getAdminPw());
	//	System.out.println(adminService.isCheckLogin(admin));
		
		Admin sessionAdmin = adminService.getAdminByIdAndPw(admin);
		if(sessionAdmin == null){
			return "redirect:/";
		}
		session.setAttribute("sessionAdmin", sessionAdmin);
		session.setAttribute("isAdmin", true);
		return "/admin/adminHome";
	}
	@RequestMapping(value="/admin/adminHome",
			method=RequestMethod.GET)
	public String adminHome(){
		return "/admin/adminHome";
	}
}
